from model import *

from datetime import date, datetime

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from google.appengine.api import users

class MainPage(webapp.RequestHandler):
  def get(self):

    user = users.get_current_user()

    if not user:
      self.redirect(users.create_login_url(self.request.uri))
      return

    products = \
        [ Product( name='Wii', description='Nintendo game console', url='www.nintendo.com' )
        , Product( name='PSP', description='PlayStation portable game console', url='www.sony.com' )
        , Product( name='knikkers', description='Knikkers', url='www.knikkersRus.nl' )
        , Product( name='xBox', description='uSoft game console', url='www.xbox.com' )
        , Product( name='paarse krokodil', description='', url='www.inflatableproducts.com' )
        ]

    for p in products: p.put()

    wishlist = \
        [ Wish( user=user, buyer='Sinterklaas'   , url='www.debootuitspanje.es/pepernoten/', product=products[0] )
        , Wish( user=user, buyer='Santa Claus'   , url='', product=products[1] )
        , Wish( user=user, buyer='de Paashaas'   , url='', product=products[2] )
    	, Wish( user=user, buyer='Repeltsteeltje', url='', product=products[3] )
    	, Wish( user=user, buyer='Klaas vaak'    , url='', product=products[4] )
	]

    for w in wishlist: w.put()

    owner = Owner( firstName='Dirk', lastName='Dreumes', birthdate=datetime(2001,1,1), user = user.email() )
    owner.put();

    self.redirect('/')

      
    
## ============================================================================

application = webapp.WSGIApplication(
                                     [('/testreset', MainPage)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
